import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      include: [/\.vue$/, /\.md$/],
      // 启用响应性语法糖
      // https://cn.vuejs.org/guide/extras/reactivity-transform.html#vite
      reactivityTransform: true
    }),
    // https://github.com/antfu/unplugin-auto-import
    AutoImport({
      // 自动导入
      imports: ['vue', 'vue/macros'],
      dts: 'src/auto-imports.d.ts',
      vueTemplate: true
    }),
    // https://github.com/antfu/unplugin-vue-components
    Components({
      dirs: ['src/components'],
      extensions: ['vue'],
      deep: true,
      directoryAsNamespace: false,
      // 用于忽略名称空间前缀的子目录路径
      globalNamespaces: [],
      // 获得 TS 自动导入组件支持，生成 components.d.ts 文件并自动更新
      dts: 'src/components.d.ts',
      // 自定义组件解析器
      resolvers: [ElementPlusResolver()],
      include: [/\.vue$/, /\.vue\?vue/, /\.md$/]
    })
  ],
  resolve: {
    alias: {
      '~/': `${path.resolve(__dirname, 'src')}/`
    }
  }
})
